package com.ibeifeng.crm.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;




import com.ibeifeng.crm.bean.Customer;
import com.ibeifeng.crm.dao.CustomerDao;

@Repository
public class CustomerDaoImpl implements CustomerDao{
	Logger log = Logger.getLogger(CustomerDaoImpl.class);
	
	@Resource
	SqlSessionFactory factory;
	@Override
	public List<Customer> queryAll() {
		List<Customer> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.CustomerNS.queryAll");
		return list;
	}
	@Override
	public int add(Customer customer) {
		int result = factory.openSession().insert("com.ibeifeng.crm.bean.mapping.CustomerNS.insert", customer);
		return result;
	}
	@Override
	public int update(Customer customer) {
		int result = factory.openSession().update("com.ibeifeng.crm.bean.mapping.CustomerNS.update", customer);
		return result;
	}
	@Override
	public int delete(Customer customer) {
		int result = factory.openSession().delete("com.ibeifeng.crm.bean.mapping.CustomerNS.delete", customer);
		
		return result;
	}
	@Override
	public Customer queryCourse(Customer customer) {
		Customer cou = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.CustomerNS.findById", customer);
		return cou;
	}
	@Override
	public int count() {
		int count = factory.openSession().selectOne("com.ibeifeng.crm.bean.mapping.CustomerNS.count");
		return count;
	}
	@Override
	public List<Customer> findAllSplit(int pg, int pgSize) {
		Map map = new HashMap();
		int start=(pg-1)*pgSize;
		int pageSize = pgSize;
		map.put("start", start);
		map.put("pageSize", pgSize);
		List<Customer> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.CustomerNS.findAllSplit",map);
		return list;
	}
	@Override
	public List<Customer> mquery(int pg, int pgSize, String keyWord) {
		Map map = new HashMap();
		int start=(pg-1)*pgSize;
		int pageSize = pgSize;
		map.put("start", start);
		map.put("pageSize", pgSize);
		map.put("keyWord", keyWord);
		List<Customer> list = factory.openSession().selectList("com.ibeifeng.crm.bean.mapping.CustomerNS.mquery",map);
		return list;
	}
	
	

}
